﻿@{
    var nhom = (List<Model.Object.Nhom>)ViewBag.nhom;
    var sanpham = (List<Model.Object.SanPham>)ViewBag.sanpham;
    var loai = (List<Model.Object.LoaiSanPham>)ViewBag.loai;
}
@*<script type="text/javascript">
    function getsp(id) {
        var URL = "/Home/Getsanphammoithem/" + id;
        $.get(URL, function (data) {
            $("#detailsp").html(data);
        });
    }
</script>*@

@*<script type="text/javascript">
    function getsp() {
        var URL = "/Home/GetJsonsanphammoi/";
        $.getJSON(URL, { Location: $("#Location").val() }, function (data) {
            var result = "";
            $.each(data, function (index, d) {

                result += '<br \>' + d;


            });
            $("#detailsp").html(result);
        });
    }
</script>*@

<div class="col-main">
    <div class="std">
        <p>
            @foreach (var n in nhom)
            {
                <div id="fb-root"></div>
                <script>                (function (d, s, id) {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (d.getElementById(id)) { return; }
                    js = d.createElement(s); js.id = id;
                    js.src = "../connect.facebook.net/en_US/all.js#xfbml=1";
                    fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));</script>
                <div class="product-slider-container">
                    <div class="clearfix title-container">
                        <h2 style="margin-top: 25px;">@n.Ten_nhom</h2>
                        <a href="#" class="jcarousel-prev-horizontal" id="shopper_carousel_prev_@n.ID"></a>
                        <a href="#" class="jcarousel-next-horizontal" id="shopper_carousel_next_@n.ID"></a>
                    </div>
                    <ul id="featured_@n.ID" class="products-grid jcarousel-skin-tango clearfix two_columns_4">
                        @for (int j = 0; j < loai.Count; j++)
                        {
                            if (loai[j].ID_Nhom == n.ID)
                            {

                                for (int i = 0; i < sanpham.Count; i++)
                                {
                                    if (sanpham[i].ID_Loaisanpham == loai[j].ID)
                                    {
                                        if (sanpham[i].HinhAnhs.FirstOrDefault() != null)
                                        {
                            <li class="item">

                                <div class="regular">
                                    <a href="@Url.Action("XemChiTietSanPham", "Home", new
                                        {
                                            id = sanpham[i].ID,
                                            loaisp = Nongsan.StringUils.UrlRewrite(loai[j].Ten_Loai),
                                            tensp = Nongsan
                                                .StringUils.UrlRewrite(sanpham[i].Ten)
                                        })" title="@sanpham[i].Ten" class="product-image">
                                        <img src="@sanpham[i].HinhAnhs.FirstOrDefault().ImagePath" data-srcx2="@sanpham[i].HinhAnhs.FirstOrDefault().ImagePath" width="252" height="252" alt="@sanpham[i].Ten" />
                                    </a>
                                    <div class="product-info">
                                        <div class="button-container">
                                            <p>
                                                <button type="button" title="Thêm vào giỏ" class="button btn-cart ajax-cart" onclick="javascript: getsp(@sanpham[i].ID);"><span><span>Thêm vào giỏ</span></span></button>
                                            </p>
                                        </div>
                                        <a class="product-name" href="@Url.Action("XemChiTietSanPham", "Home", new
                                                                 {
                                                                     id = sanpham[i].ID,
                                                                     loaisp = Nongsan.StringUils.UrlRewrite(loai[j].Ten_Loai),
                                                                     tensp = Nongsan
                                                                         .StringUils.UrlRewrite(sanpham[i].Ten)
                                                                 })" title="@sanpham[i].Ten">@sanpham[i].Ten</a>



                                        <div class="price-box">
                                            <span class="regular-price" id="product-price-"+ @sanpham[i].ID>
                                                <span class="price">@sanpham[i].Gia.ToString("0,0") đ</span><span class='unit-price'>/@sanpham[i].Don_vi_tinh</span>                                                            </span>

                                        </div>

                                    </div>
                                </div>

                                <div class="hover">
                                    <a href="@Url.Action("XemNhanhChiTietSanPham", "Home", new { id = sanpham[i].ID })" data-fancybox-group="gallery" class='fancybox quick-view' id='fancybox_@sanpham[i].ID'>Xem nhanh</a>
                                    <a href="@Url.Action("XemChiTietSanPham", "Home", new
                                        {
                                            id = sanpham[i].ID,
                                            loaisp = Nongsan.StringUils.UrlRewrite(loai[j].Ten_Loai),
                                            tensp = Nongsan
                                                .StringUils.UrlRewrite(sanpham[i].Ten)
                                        })" title="@sanpham[i].Ten" class="product-image">
                                        <img src="@sanpham[i].HinhAnhs.FirstOrDefault().ImagePath" width="252" height="252" alt="@sanpham[i].Ten" />
                                    </a>
                                    <a href="#" title="@sanpham[i].Ten">



                                        <div class="price-box">
                                            <span class="regular-price" id="product-price-3050">
                                                <span class="price">@sanpham[i].Gia đ</span><span class='unit-price'>/@sanpham[i].Don_vi_tinh</span>                                                            </span>

                                        </div>

                                    </a>
                                    <a class="product-name" href="@Url.Action("XemChiTietSanPham", "Home", new
                                                             {
                                                                 id = sanpham[i].ID,
                                                                 loaisp = Nongsan.StringUils.UrlRewrite(loai[j].Ten_Loai),
                                                                 tensp = Nongsan
                                                                     .StringUils.UrlRewrite(sanpham[i].Ten)
                                                             })" title="@sanpham[i].Ten">@sanpham[i].Ten</a>

                                    <div class="button-container">


                                        <p>
                                            <button type="button" title="Thêm vào giỏ" class="button btn-cart ajax-cart" onclick="javascript: getsp(@sanpham[i].ID);"><span><span><em></em>Thêm vào giỏ</span></span></button>
                                        </p>


                                    </div>

                                    <span class="ajax_loading" id='ajax_loading3050'>
                                        <img src='skin/frontend/shopper/default/images/ajax-loader.gif' /></span>

                                </div>

                            </li>
                                       }
                                    }
                                }
                            }
                        }
                    </ul>
                    <div class="clear"></div>
                </div>
                <script type="text/javascript">
                    //<![CDATA[


                    jQuery(document).ready(function ($) {

                        var carouselID = '#featured_@n.ID';
                        var jc = null;

                        //line up carousel items
                        var lineUp = function () {
                            var height = 0;
                            $('li.item', carouselID).each(function (i, v) {
                                $('div.product-info', this).css('height', 'auto');
                                var h = $('div.product-info', this).height();
                                if (h > height) {
                                    height = h;
                                }
                            });
                            $('li.item div.product-info', carouselID).height(height);
                        }

                        var mycarousel_initCallback = function (carousel) {
                            if (jc) {
                                return;
                            }

                            $('#shopper_carousel_prev_@n.ID').bind('click', function () {
                                carousel.next();
                                return false;
                            });
                            $('#shopper_carousel_next_@n.ID').bind('click', function () {
                                carousel.prev();
                                return false;
                            });

                            if (typeof $(carouselID).parent().swipe !== 'undefined') {
                                $(carouselID).parent().swipe({
                                    swipeLeft: function () { carousel.next(); },
                                    swipeRight: function () { carousel.prev(); },
                                    swipeMoving: function () { }
                                });
                            }

                            jc = carousel;
                        };

                        var mycarousel_reloadCallback = function (carousel) {
                            if (!isResize('featured_@n.ID')) return;
                            carousel.list = $(carouselID);
                            var li = $(carouselID).children('li');
                            carousel.list.css(carousel.lt, "0px");
                            carousel.list.css(carousel.wh, $(li.get(0)).outerWidth(!0) * li.size() + 100);
                            carousel.first = 1;
                            carousel.last = $(carouselID).parent().width() / $(li.get(0)).outerWidth(!0);
                            lineUp();
                        }

                        $(carouselID).jcarousel({
                            scroll: 1,
                            initCallback: mycarousel_initCallback,
                            reloadCallback: mycarousel_reloadCallback,
                            buttonNextHTML: null,
                            buttonPrevHTML: null
                        });

                    });

                        //]]>
                </script>

            }


        </p>
    </div>
</div>
